home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / console-screen.kbd.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2008-09-25  |  8KB  |  268 lines

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          console-screen.kbd
  4. # Required-Start:    $local_fs $remote_fs
  5. # Required-Stop:
  6. # Default-Start:     S
  7. # Default-Stop:
  8. # Description: Set console screen modes and fonts
  9. # Short-Description:    Prepare console
  10. ### END INIT INFO
  11.  
  12. # This is the boot script for the `kbd' package.
  13. # It loads parameters from /etc/kbd/config and maybe loads
  14. # default font and map.
  15. # (c) 1997 Yann Dirson
  16.  
  17. # If setupcon is present, then we've been superseded by console-setup.
  18. if type setupcon >/dev/null 2>&1; then
  19.     exit 0
  20. fi
  21.  
  22. PKG=kbd
  23. if [ -r /etc/$PKG/config ]; then
  24.     . /etc/$PKG/config
  25. fi
  26.  
  27. if [ -d /etc/$PKG/config.d ]; then
  28.     for i in `run-parts --list /etc/$PKG/config.d `; do
  29.        . $i
  30.     done
  31. fi
  32.  
  33. # do some magic with the variables for compatibility with the config
  34. # file of console-tools
  35. for vc in '' `set | grep "^.*_vc[0-9][0-9]*="  | sed 's/^.*\(_vc[0-9][0-9]*\)=.*/\1/'`
  36. do
  37.     eval [ \"\${SCREEN_FONT$vc}\" ] && eval CONSOLE_FONT$vc=\${CONSOLE_FONT$vc:-\${SCREEN_FONT$vc}}
  38.     eval [ \"\${SCREEN_FONT_MAP$vc}\" ] && eval FONT_MAP$vc=\${FONT_MAP$vc:-\${SCREEN_FONT_MAP$vc}}
  39.     eval [ \"\${APP_CHARSET_MAP$vc}\" ] && eval CONSOLE_MAP$vc=\${CONSOLE_MAP$vc:-\${APP_CHARSET_MAP$vc}}
  40. done
  41.  
  42. . /lib/lsb/init-functions
  43.  
  44. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  45. SETFONT_OPT="-v"
  46.  
  47. if which setupcon >/dev/null
  48. then
  49.     HAVE_SETUPCON=yes
  50. fi
  51.  
  52. # set DEVICE_PREFIX depending on devfs/udev
  53. if [ -d /dev/vc ]; then
  54.     DEVICE_PREFIX="/dev/vc/"
  55. else
  56.     DEVICE_PREFIX="/dev/tty"
  57. fi
  58.  
  59. # determine the system charmap
  60. CHARMAP=`LANG=$LANG LC_ALL=$LC_ALL LC_CTYPE=$LC_CTYPE locale charmap 2>/dev/null`
  61. if [ "$CHARMAP" = "UTF-8" -a -z "$CONSOLE_MAP" ]
  62. then
  63.     UNICODE_MODE=yes
  64. fi
  65.  
  66. reset_vga_palette ()
  67. {
  68.     if [ -f /proc/fb ]; then
  69.         # They have a framebuffer device.
  70.         # That means we have work to do...
  71.         echo -n "]R"
  72.     fi
  73. }
  74.  
  75. unicode_start_stop ()
  76. {
  77.     vc=$1
  78.     if [ -f /etc/environment ] || [ -f /etc/default/locale ]
  79.     then
  80.         for var in LANG LC_CTYPE LC_ALL
  81.         do
  82.             value=$(egrep "^[^#]*${var}=" /etc/environment /etc/default/locale 2>/dev/null | tail -n1 | cut -d= -f2)
  83.             eval $var=$value
  84.         done
  85.     fi
  86.     if [ -n "$UNICODE_MODE" -a -z "`eval echo \$CONSOLE_MAP_vc$vc`" ]; then
  87.         action=unicode_start
  88.     else
  89.         action=unicode_stop
  90.     fi
  91.     if [ "${CONSOLE_FONT}" ]; then
  92.         $action "${CONSOLE_FONT}" < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
  93.     else
  94.         $action < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
  95.     fi
  96. }
  97.  
  98. setup ()
  99. {
  100.     # be sure the main program is installed
  101.     which setfont >/dev/null || return
  102.  
  103.     VT="no"
  104.     # If we can't access the console, quit
  105.     CONSOLE_TYPE=`fgconsole 2>/dev/null` || return
  106.  
  107.     if [ ! $CONSOLE_TYPE = "serial" ]; then
  108.         readlink /proc/self/fd/0 | grep -q -e /dev/vc -e '/dev/tty[^p]' -e /dev/console
  109.         if [ $? -eq 0 ]; then
  110.             VT="yes"
  111.             reset_vga_palette
  112.         fi
  113.     fi
  114.  
  115.     [ $VT = "no" ] && return
  116.  
  117.     # start vcstime
  118.     if [ "${DO_VCSTIME}" = "yes" ] && which vcstime >/dev/null; then
  119.         # Different device name for 2.6 kernels and devfs
  120.         if [ `uname -r | cut -f 2 -d .` = 6 ] && [ -e /dev/.devfsd ]; then
  121.             VCSTIME_OPT="-2 /dev/vcsa0"
  122.         else
  123.             VCSTIME_OPT=""
  124.         fi
  125.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Starting clock on text console"
  126.         vcstime ${VCSTIME_OPT} &
  127.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  128.     fi
  129.  
  130.     LIST_CONSOLES=`sed -e '/^ *#/d' /etc/inittab | grep -e '\<tty[0-9]*\>' | awk -F: '{printf "%s ", $1}'`
  131.  
  132.     # Global default font+map
  133.     if [ -z "${HAVE_SETUPCON}" -a "${CONSOLE_FONT}" ]; then
  134.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up general console font"
  135.         sfm="${FONT_MAP}" && [ "$sfm" ] && sfm="-u $sfm"
  136.         acm="${CONSOLE_MAP}" && [ "$acm" ] && acm="-m $acm"
  137.     
  138.         # Set for the first 6 VCs (as they are allocated in /etc/inittab)
  139.         for vc in $LIST_CONSOLES
  140.         do
  141.             if ! ( unicode_start_stop $vc \
  142.                    && setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm ${CONSOLE_FONT} $acm )
  143.             then
  144.                 [ "$VERBOSE" != "no" ] && log_action_end_msg 1
  145.                 break
  146.             fi
  147.         done
  148.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  149.     fi
  150.  
  151.     # Default to Unicode mode for new VTs?
  152.     if [ -f /sys/module/vt/parameters/default_utf8 ]; then
  153.         if [ -n "$UNICODE_MODE" ]; then
  154.             echo 1
  155.         else
  156.             echo 0
  157.         fi > /sys/module/vt/parameters/default_utf8
  158.     fi
  159.  
  160.     # Per-VC font+sfm
  161.     PERVC_FONTS="`set | grep "^CONSOLE_FONT_vc[0-9]*="  | tr -d \' `"
  162.     if [ -z "${HAVE_SETUPCON}" -a "${PERVC_FONTS}" ]; then
  163.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC fonts"
  164.         for font in ${PERVC_FONTS}
  165.         do
  166.             # extract VC and FONTNAME info from variable setting
  167.             vc=`echo $font | cut -b16- | cut -d= -f1`
  168.             eval font=\$CONSOLE_FONT_vc$vc
  169.             # eventually find an associated SFM
  170.             eval sfm=\${FONT_MAP_vc${vc}}
  171.             [ "$sfm" ] && sfm="-u $sfm"
  172.             if ! ( unicode_start_stop $vc \
  173.                    && setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm $font )
  174.             then
  175.                 [ "$VERBOSE" != "no" ] && log_action_end_msg 1
  176.                 break
  177.             fi
  178.         done
  179.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  180.     fi
  181.  
  182.  
  183.     # Per-VC ACMs
  184.     PERVC_ACMS="`set | grep "^CONSOLE_MAP_vc[0-9]*="  | tr -d \' `"
  185.     if [ -z "${HAVE_SETUPCON}" -a "${PERVC_ACMS}" ]; then
  186.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC ACM's"
  187.         for acm in ${PERVC_ACMS}
  188.           do
  189.           # extract VC and ACM_FONTNAME info from variable setting
  190.           vc=`echo $acm | cut -b15- | cut -d= -f1`
  191.           eval acm=\$CONSOLE_MAP_vc$vc
  192.           if ! setfont -C "${DEVICE_PREFIX}$vc" ${SETFONT_OPT} -m "$acm"; then
  193.               [ "$VERBOSE" != "no" ] && log_action_end_msg 1
  194.               break
  195.           fi
  196.         done
  197.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  198.     fi
  199.     
  200.  
  201.     # screensaver stuff
  202.     setterm_args=""
  203.     if [ "$BLANK_TIME" ]; then
  204.         setterm_args="$setterm_args -blank $BLANK_TIME"
  205.     fi
  206.     if [ "$BLANK_DPMS" ]; then
  207.         setterm_args="$setterm_args -powersave $BLANK_DPMS"
  208.     fi
  209.     if [ "$POWERDOWN_TIME" ]; then
  210.         setterm_args="$setterm_args -powerdown $POWERDOWN_TIME"
  211.     fi
  212.     if [ "$setterm_args" ]; then
  213.         setterm $setterm_args 
  214.     fi
  215.  
  216.     # Keyboard rate and delay
  217.     KBDRATE_ARGS=""
  218.     if [ -n "$KEYBOARD_RATE" ]; then
  219.         KBDRATE_ARGS="-r $KEYBOARD_RATE"
  220.     fi
  221.     if [ -n "$KEYBOARD_DELAY" ]; then
  222.         KBDRATE_ARGS="$KBDRATE_ARGS -d $KEYBOARD_DELAY"
  223.     fi
  224.     if [ -n "$KBDRATE_ARGS" ]; then
  225.         [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting keyboard rate and delay"
  226.         kbdrate -s $KBDRATE_ARGS
  227.         [ "$VERBOSE" != "no" ] && log_action_end_msg 0
  228.     fi
  229.  
  230.     # Inform gpm if present, of potential changes.
  231.     if [ -f /var/run/gpm.pid ]; then
  232.         kill -WINCH `cat /var/run/gpm.pid` 2> /dev/null
  233.     fi
  234.  
  235.     # Allow user to remap keys on the console
  236.     if [ -z "${HAVE_SETUPCON}" -a -r /etc/$PKG/remap ]; then
  237.         dumpkeys < ${DEVICE_PREFIX}1 | sed -f /etc/$PKG/remap | loadkeys --quiet
  238.     fi
  239.  
  240.     # Set LEDS here
  241.     if [ -n "$LEDS" ]; then
  242.         for i in $LIST_CONSOLES
  243.         do
  244.             setleds -D $LEDS < $DEVICE_PREFIX$i
  245.         done
  246.     fi
  247. }
  248.  
  249. case "$1" in
  250.     start|reload|restart|force-reload)
  251.         if [ -n "$HAVE_SETUPCON" ]
  252.         then
  253.                 log_action_msg "Setting console screen modes"
  254.         else
  255.                 log_action_msg "Setting console screen modes and fonts"
  256.         fi
  257.         setup
  258.         ;;
  259.     stop)
  260.         ;;
  261.     *)
  262.         setup
  263.         ;;
  264. esac
  265.  
  266. :
  267.  
  268.